<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld"  prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld"  prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tlds/custom-html.tld" prefix="chtml" %>
<%@ taglib uri="/WEB-INF/tlds/struts-template.tld" prefix="template" %>

<%@ page import="com.erp.app.common.ProjectConstants"%>
<%@ page import="com.erp.framework.util.CommonUtil" %>
<%@ page import="com.erp.framework.util.user.User" %>
<%@ page import="com.erp.app.common.ProjectConstants" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.erp.app.util.web.WebUtil" %>
<%@ page import="java.util.GregorianCalendar" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.erp.framework.util.mainmenu.MenuObject" %>
<%@ page import="com.erp.app.common.ProjectConstants" %>
<%@ page import="com.erp.app.login.web.MainMenuAction" %>

<jsp:useBean id="mainMenuForm" scope="session" type="com.erp.app.login.web.MainMenuForm" />

<script>
	function doSubmitCalendarForm(pageEvent) {
		document.calendarForm.pageEvent.value = pageEvent;
		document.calendarForm.submit();
	}
	function doSubmitCalendarForm(pageEvent, pageEventSrc) {
		document.calendarForm.pageEvent.value = pageEvent;
		document.calendarForm.pageEventSrc.value = pageEventSrc;
		document.calendarForm.submit();
	}
	
</script>

<STYLE TYPE="text/css"> 
.today {font-family:Arial;font-size:10px;font-weight:bold; BACKGROUND: #929cc6} 
.normal{font-family:Arial;font-size:10px;font-weight:bold; font-name: BACKGROUND: #ffffff} 
.satday{font-family:Arial;font-size:10px;font-weight:bold; color:black} 
.sunday{font-family:Arial;font-size:10px;font-weight:bold; color:black} 
.satdayHeading{font-family:Arial;font-size:12px;font-weight:bold; color:white} 
.sundayHeading{font-family:Arial;font-size:12px;font-weight:bold; color:white} 
.normalHeading {font-family:Arial;font-size:12px;font-weight:bold; color:white} 
.buttonUpDown {font-family:Arial; font-size:10px; background-color:#2A50FE; color:#FFFFFF; width:20px; height:20px}
.buttonToday {font-family:Arial; font-size:10px; width:40px; height:20px}
</STYLE> 

<SCRIPT LANGUAGE="JavaScript"> 

var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", 
	"Oct", "Nov", "Dec"); 
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 
var days = new Array("Sun","Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); 

var fromYearPeriod = 100;
var toYearPeriod = 100;

function getDays(month, year) { 
	if (1 == month) 
		return ((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400) ? 29 : 28; 
	else 
		return daysInMonth[month]; 
} 

function getToday() { 
	this.now = new Date(); 
	this.year = this.now.getFullYear(); 
	this.month = this.now.getMonth(); 
	this.day = this.now.getDate(); 
} 


today = new getToday(); 

function newCalendar() { 

	<%	
		// add these codes for: when close the task enquiry pop up window
	    // reload the task enquiry data
		String lastAction = CommonUtil.nullToString(mainMenuForm.getPageEvent());
		String otherLastAction = CommonUtil.nullToString(mainMenuForm.getOtherPageEvent());
		String editDocType = CommonUtil.nullToString(mainMenuForm.getEditDocType());

		if (otherLastAction.equalsIgnoreCase(MainMenuAction.actionEditDoc)) {
			if(mainMenuForm.getEditDocType().equals(ProjectConstants.MOD_PROJ_FABRIC_TASK)) {
				out.println(WebUtil.openPopupFabricTaskDo(CommonUtil.nullToString(mainMenuForm.getEditTaskEnquiryEventSrc())));
			} else if(mainMenuForm.getEditDocType().equals(ProjectConstants.MOD_PROJ_STYLE_TASK)) {
				out.println(WebUtil.openPopupStyleTaskDo(CommonUtil.nullToString(mainMenuForm.getEditTaskEnquiryEventSrc())));
			}
			mainMenuForm.setPageEvent("");
			mainMenuForm.setOtherPageEvent("");
			out.println("document.forms[0].submit();");
		} 
		
		if(lastAction.equalsIgnoreCase(MainMenuAction.actionHandleOsTask)) {
//System.out.println("JSP,*********************** MAINMENU pop up Outstanding Task");
//System.out.println("JSP,*********************** MAINMENU lastAction=" + lastAction);
			out.println(WebUtil.openOsTaskSummary());
		}else if(lastAction.equalsIgnoreCase(MainMenuAction.ACTION_EDIT_ALERT_TASK)){
			out.println(WebUtil.openAlertTask());
		}
		
	%>

	today = new getToday(); 
	var parseYear = parseInt(document.all.year[document.all.year.selectedIndex].text); 
	var newCal = new Date(parseYear, document.all.month.selectedIndex, 1); 
	var day = -1; 
	var startDay = newCal.getDay(); 
	var daily = 0; 
	if ((today.year == newCal.getFullYear()) &&(today.month == newCal.getMonth())) 
	day = today.day; 
	var tableCal = document.all.calendar.tBodies.dayList; 
	var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear()); 

	for (var intWeek = 0; intWeek < tableCal.rows.length;intWeek++) {
		for (var intDay = 0;intDay < tableCal.rows[intWeek].cells.length;intDay++) { 
			var cell = tableCal.rows[intWeek].cells[intDay]; 
			if ((intDay == startDay) && (0 == daily)) 
				daily = 1; 
			if(day==daily) 
				cell.className = "today"; 
			else if(intDay==6) 
				cell.className = "sunday"; 
			else if (intDay==0) 
				cell.className ="satday"; 
			else 
				cell.className="normal"; 

			if ((daily > 0) && (daily <= intDaysInMonth)) { 
				cell.innerText = daily; 
				daily++; 
			} else 
				cell.innerText = ""; 
		} 
	}

} 

function getDate() { 
	var sDate; 
	if ("TD" == event.srcElement.tagName) {
		if ("" != event.srcElement.innerText) { 
		//date format is yyyymmdd
		sDate = document.all.year.value + padZero(document.all.month.value) + padZero(event.srcElement.innerText); 
		doSubmitCalendarForm('<%=MainMenuAction.actionHandleOsTask%>', sDate); 
		} 
	}
} 

function padZero(num) {
	var str = new String(num);
	if(str.length < 2){
		return "0" + str;
	} else {
		return str;
	}
}

function nextYear() {
	var tmpYear = document.all.year[document.all.year.selectedIndex].text;
	if(tmpYear < (today.year+toYearPeriod-1)){
		document.all.year.selectedIndex = document.all.year.selectedIndex+1;
		newCalendar();
	}
}

function prevYear() {
	var tmpYear = document.all.year[document.all.year.selectedIndex].text;
	if(tmpYear > (today.year-fromYearPeriod)){
		document.all.year.selectedIndex = document.all.year.selectedIndex-1;
		newCalendar();
	}
}

function nextMonth() {
	if((document.all.month.selectedIndex < 11) ){
		document.all.month.selectedIndex = document.all.month.selectedIndex+1;
	} else if((document.all.month.selectedIndex == 11) ){
		document.all.year.selectedIndex = document.all.year.selectedIndex+1;
		document.all.month.selectedIndex = 0
	}

	newCalendar();
}

function prevMonth() {
	if((document.all.month.selectedIndex > 0)){
		document.all.month.selectedIndex = document.all.month.selectedIndex-1;
	} else if((document.all.month.selectedIndex == 0)){
		document.all.year.selectedIndex = document.all.year.selectedIndex-1;
		document.all.month.selectedIndex = 11
	}

	newCalendar();
}

function showToday() {
	var tmpYear = new Date().getFullYear();
	var tmpMonth = new Date().getMonth();
	//index fromYearPeriod = year 2005
	document.all.year.selectedIndex = tmpYear - 2005 + fromYearPeriod - 1;
	document.all.month.selectedIndex = tmpMonth + 0;
	newCalendar();
}

function mouseOverToday(img) {
	img.src = "images/menu/btn_today_over.png";
}

function mouseOutToday(img) {
	img.src = "images/menu/btn_today_out.png";
}

function mouseOverPrev(img) {
	img.src = "images/menu/btn_l_over.png";
}

function mouseOutPrev(img) {
	img.src = "images/menu/btn_l_out.png";
}

function mouseOverNext(img) {
	img.src = "images/menu/btn_r_over.png";
}

function mouseOutNext(img) {
	img.src = "images/menu/btn_r_out.png";
}

</SCRIPT>


<input type="hidden" name="ret"> 

<TABLE ID="calendar" class="outline-table" cellspacing="0" cellpadding="0" border=0 align="right" width=70%>
  <THEAD> 
	<TR> 
	<td colspan=2>
		<a href='#'>
			<img src="images/menu/btn_today_out.png" alt="show today" onmouseover="mouseOverToday(this);" onmouseout="mouseOutToday(this);" border=0 onclick="showToday();">
		</a>
	</td>

	<TD COLSPAN=5 ALIGN=right nowrap> 

	<a href='#'>
		<img src="images/menu/btn_l_out.png" alt="prev month" onmouseover="mouseOverPrev(this);" onmouseout="mouseOutPrev(this);" border=0 onclick="prevMonth();">
	</a>

	<SELECT ID="month" ONCHANGE="newCalendar()" class="selectBox1"> 
		<SCRIPT LANGUAGE="JavaScript"> 
		for (var intLoop = 0; intLoop < months.length; intLoop++) 
			document.write("<OPTION VALUE= " + (intLoop + 1) + " " + (today.month == intLoop ? 
				"Selected" : "") + ">" + months[intLoop]); 
		</SCRIPT> 
	</SELECT> 

	<a href='#'>
		<img src="images/menu/btn_r_out.png" alt="next month" onmouseover="mouseOverNext(this);" onmouseout="mouseOutNext(this);" border=0 onclick="nextMonth();">
	</a>

	<a href='#'>
		<img src="images/menu/btn_l_out.png" alt="prev year" onmouseover="mouseOverPrev(this);" onmouseout="mouseOutPrev(this);" border=0 onclick="prevYear();">
	</a>

	<SELECT ID="year" ONCHANGE="newCalendar()" class="selectBox1"> 
		<SCRIPT LANGUAGE="JavaScript"> 
		for (var intLoop = today.year-fromYearPeriod; intLoop < (today.year + toYearPeriod); intLoop++) 
			document.write("<OPTION VALUE= " + intLoop + " " + (today.year == intLoop ? 
				"Selected" : "") + ">" + intLoop); 
		</SCRIPT> 
	</SELECT> 

	<a href='#'>
		<img src="images/menu/btn_r_out.png" alt="next year" onmouseover="mouseOverNext(this);" onmouseout="mouseOutNext(this);" border=0 onclick="nextYear();">
	</a>

	</TD> 
	</TR> 

	<TR bgcolor='#929cc6'> 
	<SCRIPT LANGUAGE="JavaScript"> 
		document.write("<TD class=satdayHeading align=center width=10% height=20>" 
			+ days[0] + "</TD>"); 
		for (var intLoop = 1; intLoop < days.length-1; 
			intLoop++) 
		document.write("<TD class=normalHeading align=center width=10% height=20>" + days[intLoop] + "</TD>"); 
		document.write("<TD class=sundayHeading align=center width=10% height=20>" + days[intLoop] + "</TD>"); 
	</SCRIPT> 
	</TR> 

</THEAD> 
<TBODY border=1 cellspacing="0" cellpadding="0" ID="dayList"ALIGN=CENTER ONCLICK="getDate()"> 
	<SCRIPT LANGUAGE="JavaScript"> 
	for (var intWeeks = 0; intWeeks < 6; intWeeks++) { 
		document.write("<TR style='cursor:hand'>"); 
		for (var intDays = 0; intDays < days.length; intDays++) {
			document.write("<TD height=20></TD>"); 
		}
		document.write("</TR>"); 
	} 
	</SCRIPT> 
</TBODY> 

</TABLE> 
<div align="center"></div>
<div align="center">
<Script Language="JavaScript1.2"> 

function Cancel() { 
document.all.ret.value = ""; 
window.close(); 
} 

</script>
</div>


<!-- NEVER call doLoad() function here, call it via its root parent jsp  -->
<body OnUnload="window.returnValue = document.all.ret.value;" onLoad="javascript:newCalendar();">

<form name="calendarForm" method="POST" action="/MSWeb/mainMenu.do">
	<input type="hidden" name="pageEvent">
	<input type="hidden" name="pageEventSrc">
</form>
